<template>
	<view>
		<uni-list>
			<uni-list-item v-for="(workReport, index) in workList" :key="index">
				<template slot="body">
					<uni-card is-full class="uni-list-card" padding="0" spacing="0">
						<view class="list-item-content">
							<view class="list-item-body">
								<view class="item-label">物料编码</view>
								<view class="u-line-1 item-value">{{ workReport.itemCode }}</view>
							</view>
							<view class="list-item-body">
								<view class="item-label">物料名称：</view>
								<view class="u-line-1 item-value">{{ workReport.itemName }}</view>
							</view>
							<view class="list-item-body">
								<view class="item-label">规格型号：</view>
								<view class="u-line-1 item-value">{{ workReport.specification }}</view>
							</view>
							<view class="list-item-body">
								<view class="item-label">单位：</view>
								<view class="u-line-1 item-value">{{ workReport.unitOfMeasure }}</view>
							</view>
							<view class="list-item-body">
								<view class="item-label">仓库：</view>
								<view class="u-line-1 item-value">{{ workReport.warehouseName }}</view>
							</view>
							<view class="list-item-body">
								<view class="item-label">库区：</view>
								<view class="u-line-1 item-value">{{ workReport.locationName }}</view>
							</view>
							<view class="list-item-body">
								<view class="item-label">库位：</view>
								<view class="u-line-1 item-value">{{ workReport.areaName }}</view>
							</view>
							<view class="list-item-body">
								<view class="item-label">批次号：</view>
								<view class="u-line-1 item-value">{{ workReport.batchCode }}</view>
							</view>
							<view class="list-item-body">
								<view class="item-label">在库数量：</view>
								<view class="u-line-1 item-value">{{ workReport.quantityOnhand }}</view>
							</view>
						</view>
					</uni-card>
				</template>
			</uni-list-item>
		</uni-list>
		<u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			status: 'loadmore',
			iconType: 'flower',
			loadText: {
				loadmore: '上拉加载更多',
				loading: '努力加载中',
				nomore: '实在没有了'
			},
			params: {
				pageNum: 1,
				pageSize: 10 //默认每次请求10条
			},
			total: '',
			workList: []
		};
	},
	onLoad(options) {
		console.log(options);
		if (JSON.stringify(options) != '{}') {
			console.log(111);
			const parmas = JSON.parse(options.params);
			this.params = parmas;
			this.getList();
		} else {
			this.getList();
		}
	},
	onReachBottom() {
		console.log('到达底部了');
		//判断是否下一页还有数据
		if (this.params.pageNum * this.params.pageSize >= this.total) {
			console.log(222);
			this.status = 'nomore';
			uni.showToast({
				title: '已全部加载完成',
				duration: 1000,
				icon: 'none'
			});
		} else {
			// 让页码值自增 +1
			this.params.pageNum += 1;
			//再次获取列表数据
			this.getList();
			this.status = 'loadmore';
		}
	},
	methods: {
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		},
		getList() {
			uni.showLoading({
				title: '加载中...',
				mask: true
			});
			this.$u.api.inventoryInquiry
				.getInventoryList(this.params)
				.then(res => {
					console.log(res);
					uni.hideLoading();
					this.workList = res.rows;
					this.total = res.total;
					if (res.total == 0) {
						uni.showToast({
							title: '暂无数据',
							duration: 2000
						});
					}
					if (res.total <= 10) {
						this.status = 'nomore';
					}
				})
				.catch(err => {
					uni.hideLoading();
					console.log(err);
				});
		}
	}
};
</script>

<style scoped lang="scss">
.uni-list-card {
}

.item-card-title-layout {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: space-between;
	margin: 0 20rpx;
	padding: 20rpx 0;
	border-bottom: 1px solid rgb(214, 215, 217);

	.item-card-title {
		font-size: 32rpx;
		color: #5a5a5a;
	}

	.item-card-status {
		padding: 5rpx 8rpx;
		font-size: 26rpx;
		color: #fff;

		&.status-1 {
			background-color: #9a9998;
		}

		&.status-2 {
			background-color: #f9ae3d;
		}

		&.status-3 {
			background-color: #3c9cff;
		}

		&.status-4 {
			background-color: #5ac725;
		}
		&.status-5 {
			background-color: #f56c6c;
		}
	}
}

.list-item-content {
	padding: 20rpx;
	border-bottom: 1px solid rgb(214, 215, 217);

	.list-item-body {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		line-height: 56rpx;

		.item-label,
		.item-value {
			color: #6a6a6a;
			font-size: 28rpx;
		}
	}
}
.card-actions {
	display: flex;
	flex-direction: row;
	align-items: center;
	.card-actions-item {
		font-size: 25rpx;
		flex: 1;
		text-align: center;
		padding: 20rpx 0;
		&.withdraw {
			color: #f56c6c;
		}
		&.division {
			border-right: 1px solid rgb(214, 215, 217);
		}
	}
}
</style>
